<!--
 * @Author: your name
 * @Date: 2022-04-12 09:34:10
 * @LastEditTime: 2022-04-12 09:50:10
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\删除数组中的undefine和null220412.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>删除数组中的null和undefined</title>
</head>
<body>
  <script>
    function clearNullArr(arr){
      for(var i=0; i<arr.length; i++){
        if(!arr[i]||arr[i]==''||arr[i]===undefined){
          arr.splice(i, 1);
          arr.length--;
          i--
        }
      }
      return arr
    }
    var geyao=["","2","3","5",undefined,null,undefined]
    console.log(clearNullArr(geyao))//["2","3","5"]
  </script>
</body>
</html>